//对axios进行二次封裝
import axios from 'axios'
//引入进度条
// import nprogress from 'nprogress'
// //引入进度条的样式
// import "nprogress/nprogress.css"

//axios的create方法创建axios实例
const requests = axios.create({
    baseURL: 'http://127.0.0.1:3000',
    timeout: 5000,
})
//请求拦截器
requests.interceptors.request.use((config) => {
    //进度条开始
    // nprogress.start()
    return config
})
//响应拦截器
requests.interceptors.response.use((res) => {
    //进度条结束
    // nprogress.done()

    //成功的回调
    return res.data;
}, () => {
    //失败的回调
    return Promise.reject(new Error('faile'))
})

export default requests